<?php

namespace App\Jobs;

use App\Jobs\Job;
use App\SendSms as SendSmsModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendSms extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    public $tries = 5;
    public $rounds;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($rounds)
    {
        // 第几轮
        $this->rounds = $rounds;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        // sleep(10);

        // 发送短信
        for ($i = 0; $i < 10; $i++) {
            sleep(1);
            $data = [
                'name' => '张三',
                'mobile' => '13500000000',
                'rounds' => $this->rounds,
                'create_time' => date('Y-m-d H:i:s', time())
            ];
            SendSmsModel::insert($data);
        }


        // log::info('发送短信');
    }
}
